package serviceImpl;

import dao.IMovieDao;
import dictionary.Dictionary;
import models.Movie;
import models.MovieTheatre;

import java.util.Date;
import java.util.List;

/**
 * Created by 国彬 on 2016/7/3.
 */
public class MovieDaoImpl implements IMovieDao {
    @Override
    public List fetchOpeningMoive(int fetch) {
        return Movie.find("status=?", Dictionary.MOVIE_STATUS_OPENING.getCode()).fetch(fetch);
    }

    @Override
    public List fetchWaitingMovie(int fetch) {
        return Movie.find("status=?", Dictionary.MOVIE_STATUS_WAITING.getCode()).fetch(fetch);
    }

    @Override
    public Movie findDetailById(String id) {
        return Movie.find("id=?",id).first();
    }

    @Override
    public Movie findMovieByDate(Date date) {
       return Movie.find("release_time=? order by score desc",date).first();
    }

    @Override
    public List findByMovieTheatreIdAndDate(String movieId,String theatreId, Date date) {
        return MovieTheatre.find("select m1,m2.startTime,m2.hallNum,m3 from Movie m1,MovieTheatre m2,TheatreHall m3 where m2.startTime>=? and m1.id=m2.movieId and m1.id=? and m2.theatreHallId=m3.id and m2.theatreId=?",date,movieId,theatreId).fetch();
    }
}
